const key = 'abs'
const el = document.getElementById('submit')
el.addEventListener('click', () => {
    const input1 = document.querySelector('.aa').value
    const input2 = document.querySelector('.bb').value
    console.log(12, input1, input2)

    const details = {
        url: 'https://www.baidu.com/',
        name: 'PSTM'
    }
    chrome.cookies.get(details, function(cookie) {
        console.log(123, cookie)
    })

    const cookieObj = {
        url: 'https://www.baidu.com/',
        name: 'abs',
        value: input1,
        httpOnly: true,
    }
    chrome.cookies.set(cookieObj)

    chrome.storage.local.get((items) => {
        // Copy the data retrieved from storage into storageCache.
        const error = chrome.runtime.lastError;
        if (error) return console.log(error);
        console.log('chrome.storage.sync.get', items);
    });

    var bgObject = chrome.extension.getBackgroundPage()
    console.log(2222, bgObject)
    bgObject.sendMessage({'token': input1})
})

// chrome.storage.local.set({[key]: 12300}, function() {
//     console.log('Notify that we saved')
// });


chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
    console.log('$on1', request)
})

// var currentTabID
chrome.tabs.query(
    {
        active: true,
        lastFocusedWindow: true
    },
    function (tabs) {
        let currentTabURL = tabs[0].url;
        currentTabID = tabs[0].id;
        // $('input', '#cookieSearchCondition').val(currentTabURL);
        document.title = document.title + "-" + currentTabURL;
        console.log(1001, currentTabID, tabs)
        // doSearch(false);
    }
);

// function doSearch() {
//     const filterURL = {
//         url: 'https://www.baidu.com/',
//     }
//     console.log(1004, filterURL)
//     chrome.cookies.getAll(filterURL, function (cks) {
//         console.log(1005, cks)
//     })
// }

// {
//     "name": "Inject Cookie",
//     "description": "This extension demonstrates a browser action with kittens.",
//     "version": "1.0",
//     "homepage_url": "http://www.editthiscookie.com/",
//     "browser_action": {
//         "default_icon": "icons/icon.png",
//         "default_title": "Inject Cookie",
//         "default_popup": "./popup.html"
//     },
//     "content_scripts": [{
//       "matches": ["<all_urls>"],
//       "js": ["popup.js"]
//     }],
//     "web_accessible_resources": [
//       {
//         "matches": ["<all_urls>"],
//         "resources": ["./contentscript.js"]
//       }
//     ],
//     "permissions": [
//         "tabs",
//         "\u003Call_urls\u003E",
//         "cookies",
//         "contextMenus",
//         "unlimitedStorage",
//         "notifications",
//         "storage",
//         "clipboardWrite"
//     ],
//     "manifest_version": 3,
//     "update_url": "http://clients2.google.com/service/update2/crx"
//   }